
// <copyright file="UrlHitStrategy.cs" company="Subhadra Software Solutions">
//   
// </copyright>
// <summary>
//   The url hit strategy.
// </summary>

namespace SubhadraSolutions.Sharp.Utils.Diagnostics
{
    using System;
    using System.Diagnostics;
    using System.Net;

    using SubhadraSolutions.Sharp.Utils.Contracts;

    /// <summary>
    /// The url hit strategy.
    /// </summary>
    public class UrlHitStrategy : IConditionStrategy
    {
        #region Public Properties

        /// <summary>
        /// Gets or sets the timeout.
        /// </summary>
        public int Timeout { get; set; }

        /// <summary>
        /// Gets or sets the url.
        /// </summary>
        public string Url { get; set; }

        #endregion Public Properties

        #region Public Methods and Operators

        /// <summary>
        /// The execute condition.
        /// </summary>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool ExecuteCondition()
        {
            WebRequest req = WebRequest.Create(this.Url);
            req.Timeout = this.Timeout;
            try
            {
                req.GetResponse();
                return true;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                return false;
            }
        }

        #endregion Public Methods and Operators
    }
}